"use strict";

var fs = require('fs-extra');
var path = require('path');
var tmp = require('tmp');
var Download = require('download');
var version = require('../package.json').version;
var appRemoteUrl = require('../package.json').appRemoteUrl.replace('%version%', version);
var spawn = require('child_process').spawn;

console.log(appRemoteUrl);

tmp.dir(function(err, zipTmpPath){

    new Download().get(appRemoteUrl)
        .dest(zipTmpPath)
        .run(function(err, files){
            unzipFile(files[0].path, path.join(__dirname, '../bin/'))
        })

})

function unzipFile(zipfile, destPath) {
    var unzip = spawn('ditto', ['-x', '-k', zipfile, destPath]);
}
